extends CharacterBody2D

# 这三个变量只是用来传递数据的, 实际的数据来自Weapon
var direction = Vector2.ZERO	# 方向
var speed = 0					# 速度
var power = 0					# 伤害

var amplitude = 20  # 波动幅度
var frequency = 10    # 波动频率
var time = 0.0         # 累积时间

@onready var animation = $AnimatedSprite2D

func _ready():
	self.rotation = direction.angle()
	if power < 2:
		animation.play("min")
	elif power < 4:
		animation.play("medium")
	else:
		animation.play("max")

func _physics_process(delta):
	time += delta
	
	# 计算垂直方向的速度分量（导数）
	var perp_dir = direction.rotated(PI/2).normalized()
	var vertical_speed = amplitude * frequency * cos(frequency * time)
	
	# 组合速度
	velocity = direction * speed + perp_dir * vertical_speed
	move_and_slide()
